import os


import os
import datetime



all_times = list()
def list_files_with_creation_time(directory):
    # 检查目录是否存在
    if not os.path.exists(directory):
        print("指定的目录不存在")
        return
    print(f"----directory_path:{directory_path}")
    # 遍历目录中的所有文件和文件夹
    for filename in os.listdir(directory):
        # 获取文件的完整路径
        filepath = os.path.join(directory, filename)
        # 检查是否为文件
        if os.path.isfile(filepath):
            # 获取文件的创建时间
            creation_time = os.path.getctime(filepath)
            # 将时间戳转换为可读的时间格式
            # all_times.append(datetime.datetime.fromtimestamp(creation_time))
            all_times.append(creation_time)
# 使用函数

directory_path = '/app/ai/data/img/移动/14/20240417'
# directory_path = '/app/ai/data/img/移动/2/20240417'
# directory_path = '/Users/daxiang/Downloads/css效果'  # 修改为你的文件夹路径
list_files_with_creation_time(directory_path)


all_times.sort()
print(f"-------all_times:{ all_times }")

pre_time = 0
next_time = 0
for item in all_times:
    if pre_time == 0:
        pre_time = item
        continue
    if next_time == 0:
        next_time = item
        continue

    print(f"-------gap:{next_time - pre_time}")
    tmp = next_time
    pre_time = tmp
    next_time = item




